#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-10-29 9:26 上午
# @Author  : yangdy
# @File    : 2020-10-29.1.字符串原地算法压缩
# @Software: PyCharmCE
from tools.my_methods import *


class Solution:
    def compress(self, chars: List[str]) -> int:
        ans = []
        if not chars:
            return ans
        w, p = chars[0], 0
        for i in range(1, len(chars)):
            if chars[i] != chars[i-1]:
                ans.append(w)
                c = i - p
                w, p = chars[i], i
                if c > 1:
                    ans.extend(list(str(c)))
                    chars[p+1:i] = list(str(c))
        ans.append(w)
        if len(chars) - p > 1:
            ans.extend(list(str(len(chars)-p)))
        print(chars)
        return ans


questions = [
    (['a', 'a', 'b', 'b', 'c', 'c', 'c'],),
    (['a'],)
]

work(questions, lambda q: Solution().compress(q[0]))
